package domain

import (
	"gitee.com/linxing_3/sr-core/yerr"
	"gitee.com/mkwchecking/sr-admin/apps/devtools/service"
	"github.com/spf13/cobra"
)

var domainCmd = &cobra.Command{
	Use:     "domain",
	Short:   "domain commands",
	Long:    `domain commands`,
	PreRunE: dependsCheck,
}

func init() {
	domainCmd.AddCommand(domainAddCmd)
}

func GetDomainCmd(builder func(string) (*service.DevtoolsSvc, error)) *cobra.Command {
	svcBuilder = builder
	return domainCmd
}

func dependsCheck(cmd *cobra.Command, args []string) error {
	if svc == nil {
		// tableArg.Parse(cmd)
		if cfg == "" {
			return yerr.ErrBizParamInvalid.Errorf("arg (-c/--config $CONFIG_PATH) is required")
		}
		var err error
		svc, err = svcBuilder(cfg)
		return err
	}
	return nil
}
